import 'dart:convert';

import 'package:base_lib/common/index.dart';
import 'package:base_lib/config.dart';
import 'package:doctor_examine_lib/hospital_list/hospital_list_entity.dart'
    as HospitalBean;
import 'package:doctor_examine_lib/examine_list/examine_list_entity.dart'
    as ExamineBean;
import 'package:doctor_examine_lib/repository/examine_net_intercept.dart';

class DoctorExamineHttp {
  static HttpManager _httpProxyIns;

  static createHttpProxy(
      {mBaseUrl = Config.doctorBaseUrl,
      codeName = Config.codeName,
      codeSuccessValue = Config.codeSuccessValue,
      msgName = Config.msgName,
      reqTimeOut = Config.reqTimeOut,
      respTimeOut = Config.respTimeOut,
      logTag = "prescribe"}) {
    _httpProxyIns = HttpManager(mBaseUrl,
        CODE_NAME: codeName,
        CODE_SUCCESS_VALUE: codeSuccessValue,
        MSG_NAME: msgName,
        REQ_TIME_OUT: reqTimeOut,
        RESP_TIME_OUT: respTimeOut,
        LOG_TAG: logTag,
        defaultInterceptors: [ExamineNetIntercept()]);
  }

  /// 查询医生附近的医院列表信息
  static const PEACHUSER_GET_DOCTORINFO_DOCTORHOSPITALANDAROUNDHOSPITAL =
      "api/peachUser/doctorInfo/getDoctorHospitalAndAroundHospital";

  /// 获取医院开通的检查项目列表
  static const TRANSFER_GET_EXAMINEHOSPITAL_CLASSLIST =
      "api/transfer/examineHospital/getHospitalClassList";

  /// 获取医院开通的某一项检查项目的子项目
  static const TRANSFER_GET_EXAMINEHOSPITAL_SUBITEM =
      "api/transfer/examineHospital/queryHospitalItemByClass";

  /// 线下新建检查单
  static const TRANSFER_POST_EXAMINEORDER_ADDORDER_QUICKLY =
      "api/transfer/examineOrder/addOrderQuickly";

  /// 获取当前医生的所有患者
  static Future<ResultBody<List<HospitalBean.Datum>>> getDoctorHospital(
      Map<String, dynamic> queryParams) {
    return _httpProxyIns.get<List<HospitalBean.Datum>>(
        PEACHUSER_GET_DOCTORINFO_DOCTORHOSPITALANDAROUNDHOSPITAL, (resMap) {
      return HospitalBean.HospitalListEntity.fromJson(resMap).data;
    }, queryParams: queryParams);
  }

  /// 获取医院开通的检查项目列表
  static Future<ResultBody<List<ExamineBean.Datum>>> getHospitalClassList(
      Map<String, dynamic> queryParams) {
    return _httpProxyIns.get<List<ExamineBean.Datum>>(
        TRANSFER_GET_EXAMINEHOSPITAL_CLASSLIST, (resMap) {
      return ExamineBean.ExamineEntity.fromJson(resMap).data;
    }, queryParams: queryParams);
  }

  /// 获取医院开通的检查项目列表
  static Future<ResultBody<List<ExamineBean.SubDatum>>>
      queryHospitalItemByClass(Map<String, dynamic> queryParams) {
    return _httpProxyIns.get<List<ExamineBean.SubDatum>>(
        TRANSFER_GET_EXAMINEHOSPITAL_SUBITEM, (resMap) {
      return ExamineBean.ExamineSubEntity.fromJson(resMap).data;
    }, queryParams: queryParams);
  }

  /// 线下新建检查单
  static Future offlineCreateExamineOrder(Map<String, dynamic> params) {
    return _httpProxyIns.postJson(TRANSFER_POST_EXAMINEORDER_ADDORDER_QUICKLY,
        (resMap) {
      return resMap;
    }, jsonData: json.encode(params));
  }
}
